﻿<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hui</title>
     <link rel="stylesheet" type="text/css" href="../css/app.css" />
    <link rel="stylesheet" type="text/css" href="../css/iconfont.css" />
    
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.12.0.min.js"></script>
	<script type="text/javascript" src="../script/app.js" ></script>
    <style type="text/css">
        
        body { height:100%; }

    </style>
</head>
<body class=" H-box-sizing-border-box H-overflow-hidden H-theme-background-color-497bf0">

    <div class=" winu-logo H-center-all" style="padding-top:60px;height: 90px;">

		<div class="H-text-align-center">
            <img onclick="browseuser();" id="portrait" src="../image/logo.png" class="H-position-relative H-display-block H-border-radius-circle H-height-90" />
        
        </div>
        
        
    </div>
    
    <div class="H-flexbox-horizontal H-text-align-center  H-padding-vertical-both-15" style="margin-top:80px;height: 90px;">
        <div class="H-flex-item">
            <span onclick="qqLogin();" class="H-icon H-center-all H-theme-background-color1 H-border-radius-circle H-margin-horizontal-auto" style="height: 42px; width: 42px; "><i class="H-iconfont H-icon-qq H-font-size-26 H-theme-font-color-white"></i></span>
            <label class="H-display-block H-font-size-14 H-margin-vertical-top-5">腾讯QQ</label>
        </div>
        <div class="H-flex-item">
            <span onclick="wxLogin();" class="H-icon H-center-all H-theme-background-color9 H-border-radius-circle H-margin-horizontal-auto" style="height: 42px; width: 42px; "><i class="H-iconfont H-icon-weixin H-font-size-26 H-theme-font-color-white"></i></span>
            <label class="H-display-block H-font-size-14 H-margin-vertical-top-5">微信</label>
        </div>
        
    </div>
    <div class="H-padding-vertical-bottom-10"></div>

   
    <script type="text/javascript">
    	apiready = function(){
    		
    	}
    	
    	
    	function login( user , auth_type ){
    		var system = api.systemType;
    		var device_id = api.deviceId;
    		
    		$app.ajax($app.serverUrl+"index/user/login",{
    			'openid' :user.openid,
    			'nickname' :user.nickname,
    			'headimgurl' :user.headimgurl,
    			'system'   :system,
    			'device_id':device_id,
    			'type':auth_type
    		},'post',function(ret){
    			if( ret.status == 1000){
    				$api.setStorage('userinfo',ret.data);
					localStorage.setItem('username',ret.data.nickname);
					localStorage.setItem('token',ret.data.token);
					localStorage.setItem('portrait',ret.data.portrait);
					
					localStorage.setItem('last_login_type',auth_type);
					
					api.sendEvent({
	                    name:'push_user_info'
                    });
					api.closeWin();
    			} else {
    				$app.toast( ret.msg );
    			}
    		});
    	}
    	
    	function qqLogin(){
    	
    		var qq = api.require('QQPlus');
			qq.installed(function(ret, err) {
			    if (ret.status) {
			        qq.login(function(log, err) {
			        	if (log.status) {
					        
					        qq.getUserInfo(function(info, err) {
							    if (info.status) {
							    	var result = info.info;
							        $api.setStorage('qq_user',result);
							        var userss = $.parseJSON(result);
							        userss.openid = log.openId ;
							        userss.headimgurl=userss.figureurl_qq_2;
							        
							        console.log(JSON.stringify(userss));
							        login(userss ,1);
							    } else {
							        api.alert({ msg: err.msg });
							    }
							});
					        
					    } else {
					        api.alert({ msg: err });
					    }

					});
			        
				
			    } else {
			        $app.toast('当前设备未安装QQ客户端');
			    }
			});
    	}
    	
    	function wxLogin(){
    		var wx = api.require('wx');
			wx.isInstalled(function(ret, err) {
			    if (ret.installed) {
			        wx.auth({
					    apiKey: ''
					}, function(ret, err) {
					    if (ret.status) {
					       wx.getToken({
							    apiKey: '',
							    apiSecret: '',
							    code: ret.code
							}, function(ret, err) {
							    if (ret.status) {
							        wx.getUserInfo({
									    accessToken: ret.accessToken,
									    openId: ret.openId
									}, function(user, usererr) {
									    if (user.status) {
									    	$api.setStorage('wx_user',user);
									        login(user ,2);
									    } else {
									        alert(usererr.code);
									    }
									});
							    } else {
							        alert(err.code);
							    }
							});
					    } else {
					        $app.toast('授权失败');
					    }
					});
			    } else {
			        $app.toast('当前设备未安装微信客户端');
			    }
			});
    	}
    	
    	
    	
    	
    	
    	function _openWinHead(name,url,title){
			
			_openWinByUrl(name+'window_head','./window_head',{'fname':name,'furl':url,'title':title});
		}
    
    </script>
</body>
</html>